<%-- 
    Document   : quran
    Created on : Oct 21, 2010, 12:28:29 PM
    Author     : M Bilal
--%>

<%@ page import="wap.rockvilletech.portal.DBProc" %>
<%@ page import="java.io.*,java.util.*,java.text.*" %>

<%@ page import="org.apache.log4j.Logger" %>
<% final Logger log = Logger.getLogger("JSP.QURAN"); %>
<%@include file="../includes/header.jspf"%>

<%
thisPage="Religon-Quran";
response.setContentType("text/html");
DBProc dbp = DBProc.getInstance();
Vector vQuran = new Vector();

// Vars for PAGING
int intBlockLength = 10;
int intRecordsToBeDisplayed = 0,
    intRecordsToBeFetched = 0;
String strPagingLinks = "";

boolean computePaging = false,
        isNext = true;
int intRecCount = 0,
    intPageID = 0,
    intLastPage = 0;
try { intPageID = Integer.parseInt( request.getParameter("pid").trim() ); /* Page ID */ } catch (Exception ex) { intPageID = 0; }

String  id = "", CatID = "", pid = "", bid = "";
boolean isList = false;


id = request.getParameter("id") != null ? request.getParameter("id").toString() : "";
CatID = request.getParameter("CatID") != null ? request.getParameter("CatID").toString() : "";
pid = request.getParameter("pid") != null ? request.getParameter("pid").toString() : "0";
bid = request.getParameter("bid") != null ? request.getParameter("bid").toString() : "";

if(request.getParameter("arg0") == null || request.getParameter("arg0").equalsIgnoreCase("null")) {

    try{

        vQuran=dbp.getQuran(pid, 0);
        intRecCount =(Integer)vQuran.get(0);
        intRecordsToBeDisplayed =intRecordsToBeFetched=(Integer)vQuran.get(1);
        isList = true;
        }catch(Exception e){}

}else{
    try {
        int arg=Integer.parseInt(request.getParameter("arg0"));
         intPageID=intPageID==0?intPageID=1:intPageID;
        intPageID = Integer.parseInt(pid)>0?intPageID=intPageID+1:intPageID;
        vQuran = dbp.getQuran(Integer.toString(intPageID), arg);

        intRecCount = (Integer)(vQuran.get(0));
        intRecordsToBeDisplayed = intRecordsToBeFetched=(Integer)(vQuran.get(1));

    } catch (Exception ex) { }

}

if(isList) {
    //check if list of books to be displayed
    try {
        intLastPage=intRecCount/intRecordsToBeDisplayed;
        intPageID= Integer.parseInt(pid.toString());
        if (intPageID > intLastPage) intPageID = intLastPage;

        if (vQuran.size()+1 < intRecordsToBeFetched) {
            intRecordsToBeDisplayed -= (intRecordsToBeFetched - vQuran.size());
            intRecordsToBeFetched = vQuran.size();
            isNext = false;
        }
      } catch (Exception ex) { }
}else {
    try {
        intLastPage = intRecCount-1;
        intPageID= Integer.parseInt(pid.toString());
        if (intPageID > intLastPage) intPageID = intLastPage;
        intRecordsToBeFetched=1;
        intRecordsToBeDisplayed = 1;
        isNext=Integer.parseInt(pid)== intRecCount-1?false:true;

    } catch (Exception ex) { }
}

computePaging = vQuran.size() == 0 ? false : true;

if (computePaging) {
    // Call the method which will generate Page links
    wap.rockvilletech.util.Paging.computePaging(request, "quran.jsp?", intRecordsToBeFetched, intRecordsToBeDisplayed,
                     intRecCount, intBlockLength, intLastPage, intPageID, isNext);

    // Get the generated Summary and links
    strPagingLinks = wap.rockvilletech.util.Paging.getPagingLinks();
}
%>

<div style="padding: 5px 0px 0px 0px;">
    <div class="div_navigation" id="div_navigation">
        <a href="<%=context_Path%>" class="LinkIndex">Home</a>&nbsp;&gt;
        <a href="<%=context_Path%>/religion/index.jsp" class="LinkIndex">Religion</a>&nbsp;&gt;
        <span class="navigation_Leaf">Quran</span>
    </div>
</div>
    
        <table width="100%" align="left" cellpadding="0" cellspacing="0" style="text-align: left;font-weight: bold;">
                        <tr>
                            <td style="background-image:url('../images/new/top_bar_02.jpg');background-repeat: repeat-x;height:26px;">
                                <b style="padding:0px 0px 0px 2px;">&nbsp;Quran&nbsp;</b>
                            </td>
                        </tr>
         </table>
    


<div style="height:1px;clear: both;"> &nbsp; </div>
<div style="padding:5px 0px 0px 2px;" align="left">
<%
if(isList){
    for(int i=2;i<vQuran.size();i++){
        String[] temp = (String[])vQuran.get(i);
%>
    <a class="" href="<%=context_Path%>/religion/quran.jsp?src=<%=temp[1]%>&id=<%=id%>&pid=0&CatID=<%=CatID%>&bid=0&arg0=<%=temp[2]%>">
        <img src="<%=context_Path%>/images/bullet-dot-green.png" alt=""/>&nbsp;<%=temp[1]%>
    </a><br/>
<%
    }
}else{
    for(int y=1;y<=vQuran.size()-2;y++){
        String[] temp = (String[])vQuran.get(y+1);
        if(y==1){
%>
        <b>Source:</b>&nbsp;<%=temp[1]%><br/>
        <b>Surah:</b>&nbsp;<%=temp[5]%><br/>
        <b>Aayah:</b>&nbsp;<%=intPageID+1%><br/>
        <%=temp[0]%>
        <%
        }else{
            out.println(temp[0]);
        }
%>
        <br/>
<%
    }
    app="Quran-Content";
}
%>

</div>
<div class="divStepFoot"><%=strPagingLinks%></div>

<%@include file="../includes/footer.jspf"%>


<%
wpb.LogVisit(strIP, thisPage, strGsm, strApn, strBrand, strModel, app, request.getQueryString());
%>